package com.guofen.service.sjq.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guofen.dao.SjqSolidliquidProduceInspectionEquipmentMapper;
import com.guofen.pojo.SjqSolidliquidProduceElectricity;
import com.guofen.pojo.SjqSolidliquidProduceInspectionEquipment;
import com.guofen.service.sjq.SjqSolidliquidProduceInspectionEquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SjqSolidliquidProduceInspectionEquipmentServiceImpl implements SjqSolidliquidProduceInspectionEquipmentService {
    @Autowired
    SjqSolidliquidProduceInspectionEquipmentMapper sjqSolidliquidProduceInspectionEquipmentMapper;

    @Override
    public boolean add(String name,String detail,Boolean isNormal){
        SjqSolidliquidProduceInspectionEquipment sjqSolidliquidProduceInspectionEquipment = new SjqSolidliquidProduceInspectionEquipment();
        sjqSolidliquidProduceInspectionEquipment.setDetail(detail);
        sjqSolidliquidProduceInspectionEquipment.setName(name);
        sjqSolidliquidProduceInspectionEquipment.setIsNormal(isNormal);
        System.out.println(detail+"  "+name);
        int result = sjqSolidliquidProduceInspectionEquipmentMapper.insert(sjqSolidliquidProduceInspectionEquipment);
        if (result == 1)
            return true;
        else
            return false;
    }

    @Override
    public SjqSolidliquidProduceInspectionEquipment selectByPrimaryKey(Integer key){
        return sjqSolidliquidProduceInspectionEquipmentMapper.selectByPrimaryKey(key);
    }

    @Override
    public List<SjqSolidliquidProduceInspectionEquipment> getlist(){
        return sjqSolidliquidProduceInspectionEquipmentMapper.getlist();
    }

    @Override
    public Map<String, Object> get(int pageSize, int currentPage) {
        Map<String, Object> map = new HashMap<>();
        PageHelper.startPage(currentPage, pageSize);
        List<SjqSolidliquidProduceInspectionEquipment> list = sjqSolidliquidProduceInspectionEquipmentMapper.selectAll();
        PageInfo pageRecord = new PageInfo(list);
        long sum = pageRecord.getTotal();
        list = pageRecord.getList();
        map.put("records",list);
        map.put("sum",sum);
        return map;
    }


    // 弃用，InspectionEquipment无任何时间属性
    @Override
    public Map<String, Object> getByTime(int pageSize, int currentPage, long startTime, long endTime) {
        Map<String, Object> map = new HashMap<>();
        PageHelper.startPage(currentPage, pageSize);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String startDate = dateFormat.format(new Date(startTime));
        String endDate = dateFormat.format(new Date(endTime));
        List<SjqSolidliquidProduceInspectionEquipment> list = sjqSolidliquidProduceInspectionEquipmentMapper.selectByDate(startDate, endDate);
        PageInfo pageRecord = new PageInfo(list);
        long sum = pageRecord.getTotal();
        list = pageRecord.getList();
        map.put("records",list);
        map.put("sum",sum);
        return map;
    }

    @Override
    public int delete(int id) {
        return sjqSolidliquidProduceInspectionEquipmentMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(SjqSolidliquidProduceInspectionEquipment record) {
        return sjqSolidliquidProduceInspectionEquipmentMapper.updateByPrimaryKeySelective(record);
    }

}
